package cn.edu.sgu.www.mhxysy.controller.chongwu;

import cn.edu.sgu.www.mhxysy.consts.CustomConstants;
import cn.edu.sgu.www.mhxysy.consts.CustomMessages;
import cn.edu.sgu.www.mhxysy.consts.MimeTypes;
import cn.edu.sgu.www.mhxysy.dto.chongwu.ChongwuInitZizhiDTO;
import cn.edu.sgu.www.mhxysy.dto.chongwu.ChongwuInitZizhiOrdinaryDTO;
import cn.edu.sgu.www.mhxysy.dto.chongwu.ChongwuInitZizhiSpecialDTO;
import cn.edu.sgu.www.mhxysy.entity.chongwu.ChongwuInitZizhi;
import cn.edu.sgu.www.mhxysy.pager.chongwu.ChongwuInitZizhiPager;
import cn.edu.sgu.www.mhxysy.restful.JsonPage;
import cn.edu.sgu.www.mhxysy.restful.JsonResult;
import cn.edu.sgu.www.mhxysy.service.chongwu.ChongwuInitZizhiService;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.github.xiaoymin.knife4j.annotations.ApiSupport;
import io.swagger.annotations.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.constraints.NotNull;
import java.util.List;

/**
 * @author 沐雨橙风ιε
 * @version 1.0
 */
@Api(tags = "宠物初始资质管理")
@ApiSupport(author = CustomConstants.AUTHOR)
@Validated
@RestController
@RequestMapping(path = "/chongwu_init_zizhi", produces = MimeTypes.APPLICATION_JSON_CHARSET_UTF_8)
public class ChongwuInitZizhiController {

	private final ChongwuInitZizhiService chongwuInitZizhiService;

	@Autowired
	public ChongwuInitZizhiController(ChongwuInitZizhiService chongwuInitZizhiService) {
		this.chongwuInitZizhiService = chongwuInitZizhiService;
	}

	@ApiOperation("添加宠物初始资质")
	@RequestMapping(value = "/insert", method = RequestMethod.POST)
	public JsonResult<Void> insert(@Validated ChongwuInitZizhiDTO chongwuInitZizhiDTO) {
		chongwuInitZizhiService.insert(chongwuInitZizhiDTO);

		return JsonResult.success(CustomMessages.INSERT_SUCCESS);
	}

	@ApiOperation("通过ID删除宠物初始资质")
	@RequestMapping(value = "/deleteById", method = RequestMethod.POST)
	public JsonResult<Void> deleteById(
			@ApiParam(name = "id", value = "宠物初始资质ID", required = true)
			@NotNull(message = CustomMessages.ID_NOT_NULL) Integer id) {
		chongwuInitZizhiService.deleteById(id);

		return JsonResult.success(CustomMessages.DELETE_SUCCESS);
	}

	@ApiOperation("通过ID修改宠物初始资质")
	@RequestMapping(value = "/updateById", method = RequestMethod.POST)
	public JsonResult<Void> updateById(@Validated ChongwuInitZizhiDTO chongwuInitZizhiDTO) {
		chongwuInitZizhiService.updateById(chongwuInitZizhiDTO);

		return JsonResult.success(CustomMessages.UPDATE_SUCCESS);
	}

	@ApiOperation("保存宠物初始资质")
	@RequestMapping(value = "/save", method = RequestMethod.POST)
	public JsonResult<Void> save(@Validated ChongwuInitZizhiOrdinaryDTO chongwuInitZizhiOrdinaryDTO) {
		chongwuInitZizhiService.save(chongwuInitZizhiOrdinaryDTO);

		return JsonResult.success(CustomMessages.SAVE_SUCCESS);
	}

	@ApiOperation("保存特殊宠物的初始资质")
	@RequestMapping(value = "/saveSpecial", method = RequestMethod.POST)
	public JsonResult<Void> saveSpecial(@Validated ChongwuInitZizhiSpecialDTO chongwuInitZizhiSpecialDTO) {
		chongwuInitZizhiService.saveSpecial(chongwuInitZizhiSpecialDTO);

		return JsonResult.success(CustomMessages.SAVE_SUCCESS);
	}

	@ApiOperation("查询特殊宠物的初始资质")
	@RequestMapping(value = "/selectSpecials", method = RequestMethod.GET)
	public JsonResult<List<ChongwuInitZizhi>> selectSpecials(
			@ApiParam(name = "specialType", value = "特殊类型", required = true)
			@NotNull(message = "特殊类型不能为空") Integer specialType) {
		List<ChongwuInitZizhi> list = chongwuInitZizhiService.selectSpecials(specialType);

		return JsonResult.success(null, list);
	}

	@ApiOperation("查询宠物初始资质列表")
	@ApiImplicitParams({
			@ApiImplicitParam(name = "type", value = "资质类型", required = false),
			@ApiImplicitParam(name = "chongwuId", value = "宠物类型ID", required = true)
	})
	@RequestMapping(value = "/selectList", method = RequestMethod.GET)
	public JsonResult<List<ChongwuInitZizhi>> selectByChongwuId(
			@RequestParam(required = false) Integer type,
			@NotNull(message = CustomMessages.CHONGWU_CATEGORY_ID_NOT_NULL) Integer chongwuId) {
		List<ChongwuInitZizhi> list = chongwuInitZizhiService.selectList(type, chongwuId);

		return JsonResult.success(null, list);
	}

	@ApiOperation("分页查询宠物初始资质列表")
	@RequestMapping(value = "/selectByPage", method = RequestMethod.GET)
	public JsonResult<JsonPage<ChongwuInitZizhi>> selectByPage(ChongwuInitZizhiPager pager) {
		Page<ChongwuInitZizhi> page = chongwuInitZizhiService.selectByPage(pager);

		return JsonResult.restPage(page);
	}

}